package edu.ntnu.controller;

/**
 * Class represents point in map
 */
public class Point {
	
	private int x;
	private int y;
	
	public Point(int newX, int newY) {
		x = newX;
		y = newY;
	}
	
	public Point(Point template) {
		this(template.x, template.y);
	}
	
	/**
	 * Get point in exact direction and exact distance from this point
	 * @param degree	direction to new point
	 * @param distance	distance to new point
	 * @return 			new point in given direction and distance
	 */
	public Point getAnother(int degree, int distance) {
if(distance < 0) {
	distance = distance * -1;
	degree = degree + 180;
}
		double rad = Math.toRadians(degree);
		// because of BUG in Math.cos(-PI/2)
		double cos = ((degree + 90) % 180 == 0) ? 0 : Math.cos(rad);
		double sin = (degree % 180 == 0) ? 0 : Math.sin(rad);
		Double newX = x + distance * cos;
		Double newY = y + distance * sin;
		return new Point(newX.intValue(), newY.intValue());
	}
	
	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setX(int newX) {
		x = newX;
	}
	
	public void setY(int newY) {
		y = newY;
	}
	
	public void set(int newX, int newY) {
		this.setX(newX);
		this.setY(newY);
	}
	
	@Override
	public boolean equals(Object other) {
        if (other instanceof Point) {
            Point otherPoint = (Point) other;
            return (x == otherPoint.x && y == otherPoint.y);
        }
        return false;
	}
	
	@Override
	public int hashCode() {
		return (x * 3 + y * 7) * 11;
	}
	
	@Override
	public String toString() {
		return ("[" + x + ", " + y + "]");
	}
}
